package com.ruirui;


import com.ruirui.demo.ab.Ab;
import com.ruirui.demo.strategy.GradingStrategy;
import com.ruirui.demo.strategy.context.GradingFactory;
import com.ruirui.demo.strategy.entity.Answer;
import com.ruirui.demo.strategy.entity.Question;
import com.ruirui.demo.strategy.entity.QuestionType;
import com.ruirui.demo.strategy.impl.EssayStrategy;
import com.ruirui.demo.strategy.impl.SingleChoiceStrategy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class SpringTestMain {
    public static void main(String[] args) throws  InterruptedException{


        // 1. 启动 Spring 容器
        ConfigurableApplicationContext bean = SpringApplication.run(SpringTestMain.class, args);

        // 2. 从容器中获取策略工厂
        GradingFactory sf = bean.getBean(GradingFactory.class);

        // 3. 构造一道单选题及其答案
        Question q1 = new Question(1L, "Java 是什么类型语言？", QuestionType.SINGLE_CHOICE, "A", 5);
        Answer a1 = new Answer("A");

        // 4. 根据题目类型获取对应的评分策略
        GradingStrategy strategy1 = sf.getStrategy(q1);

        // 5. 执行评分并打印结果
        int grade = strategy1.grade(q1, a1);
        System.out.println(grade);

        Ab ab = new Ab() {
            @Override
            public void show() {
                super.show();
            }
        };
    }

}